home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / AlexNeXTSTEPSource / Source / Chapter6_Events / DelegateDemo / DelegateDemo_main.m < prev    next >
Text File  |  1995-06-12  |  1KB  |  57 lines

  1. #import <appkit/appkit.h>
  2. #import "WindowDelegate.h"
  3.  
  4. // minimal program to demonstrate the
  5. // windowWillClose: method
  6.  
  7. main()
  8. {
  9.     // create an application object
  10.     // to establish connection to
  11.     // Window Server
  12.     id NXApp = [Application new];
  13.     id theWindow;
  14.     id theMenu;
  15.     id theWindowDelegate;
  16.     NXRect theRect;
  17.     NXSize theSize;
  18.  
  19.     // create a window that's at 125, 125
  20.     // and is 200 by 300 pixels
  21.     NXSetRect(&theRect, 125, 125, 200, 300);
  22.     theWindow = [ [Window alloc]
  23.         initContent:&theRect
  24.         style:NX_RESIZEBARSTYLE
  25.         backing:NX_BUFFERED
  26.         buttonMask:NX_CLOSEBUTTONMASK
  27.         defer:YES];
  28.  
  29.     // set the minimum size of window
  30.     theSize.width = 100;
  31.     theSize.height = 100;
  32.     [theWindow setMinSize:&theSize];
  33.  
  34.     // create the menu
  35.     theMenu = [ [Menu alloc]
  36.         initTitle: [NXApp appName]];
  37.     // create the menu option
  38.     [theMenu addItem:"Quit"
  39.         action:@selector(terminate:)
  40.         keyEquivalent:'q'];
  41.  
  42.     // resize menu to accommodate menu option
  43.     [theMenu sizeToFit];
  44.     [NXApp setMainMenu:theMenu];
  45.  
  46.     theWindowDelegate =
  47.         [ [WindowDelegate alloc] init];
  48.     [theWindow setDelegate:theWindowDelegate];
  49.  
  50.     // send the window to the front
  51.     // and display it
  52.     [theWindow makeKeyAndOrderFront:nil];
  53.  
  54.     // go into event loop to wait for events
  55.     [NXApp run];
  56. }
  57.